<?php
/**
 * PageController.php
 *
 * @category    Madoqua
 * @package     Module
 * @subpackage  Blog
 */

/** base class */
require_once 'Madoqua/Controller/Action/Abstract.php';

/**
 * Blog_PageController
 *
 * @category    Madoqua
 * @package     Module
 * @subpackage  Blog
 */
class Blog_PageController extends Madoqua_Controller_Action_Abstract
{

    /**
     * page model
     *
     * @var Blog_Page
     */
    private $_pageModel;

    /**
     * initialization
     */
    public function init()
    {
        parent::init();
        //bubblez!

        $this->_modelLoader->load(array('Blog_Page'));
        $this->_pageModel = new Blog_Page();
        //load/set page model
    }

    /**
     * read a page
     */
    public function readAction()
    {
        $slug = $this->_getParam('slug');
        $id = (int) $this->_getParam('id');
        //slug and/or id from the params

        if (!empty($slug)) {
            $page = $this->_pageModel->fetchBySlug($slug);
        } elseif (!empty($id)) {
            $page = $this->_pageModel->fetchById($id);
        } else {
            throw new Exception('No slug or id');
        }
        //find post using slug or id and throw an exception if both aren't set

        $this->view->page = $page;
    }

    /**
     * list pages
     */
    public function listAction()
    {
        $this->view->pages = $this->_pageModel->fetchAll();
    }

    /**
     * list page titles
     */
    public function overviewAction() {
        $count = $this->_getParam('count', null);
        //get count

        $this->view->pages = $this->_pageModel->fetchAll(null, null, $count);
    }
}